package com.reguang.result;

import java.io.Serializable;

import com.reguang.enums.ResultCode;

/**
 * 
 * <p>Title: Result</p>
 * <p>Description: 平台通用返回结果</p>
 * @author weibiao
 * @date 2019年12月24日
 */
public class Result implements Serializable {

	/** serialVersionUID*/
	private static final long serialVersionUID = -1919328348539364620L;

	private Integer code;

	private String msg;

	private Object data;
	
	

	public static Result failure() {
		return failure("操作失败");
	}

	public static Result success() {
		Result result = new Result();
		result.setResultCode(ResultCode.SUCCESS);
		return result;
	}

	public static Result success(Object data) {
		Result result = new Result();
		result.setResultCode(ResultCode.SUCCESS);
		result.setData(data);
		return result;
	}

	public static Result failure(ResultCode resultCode) {
		Result result = new Result();
		result.setResultCode(resultCode);
		return result;
	}

	public static Result failure(ResultCode resultCode, Object data) {
		Result result = new Result();
		result.setResultCode(resultCode);
		result.setData(data);
		return result;
	}

	public static Result failure(String message) {
		Result result = new Result();
		result.setCode(ResultCode.SPECIFIED_QUESTIONED_USER_NOT_EXIST.code());
		result.setMsg(message);
		return result;
	}

	private void setResultCode(ResultCode code) {
		this.code = code.code();
		this.msg = code.message();
	}

	public Integer getCode() {
		return code;
	}

	public void setCode(Integer code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}
}
